<template>
    <div class="user-info-panel">
        <!-- 用户基本信息 -->
        <div class="user-info-panel__header">
            <div class="user-info-panel__details">
                <div class="user-info-panel__name">{{ userName }}</div>
            </div>
            <img :src="userAvatar" :alt="userAvatarAlt" class="user-info-panel__avatar-image" />
        </div>
        <div class="user-info-panel__org">{{ userOrganization }}</div>
        <!-- 功能菜单 -->
        <div class="user-info-panel__menu">
            <span class="user-info-panel__menu-btn" @click="handlePersonalSettings">个人设置</span>
            <span class="user-info-panel__menu-btn" @click="handleLogout">退出</span>
        </div>
    </div>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
    userName: {
        type: String,
        default: '苗传伟'
    },
    userAvatar: {
        type: String,
        default: '/favicon.ico'
    },
    userAvatarAlt: {
        type: String,
        default: '用户头像'
    },
    userOrganization: {
        type: String,
        default: '默认组织'
    }
})

const emit = defineEmits(['personal-settings', 'logout'])

// 处理个人设置点击
const handlePersonalSettings = () => {
    emit('personal-settings')
}

// 处理退出点击
const handleLogout = () => {
    emit('logout')
}
</script>
<style lang="scss">
.user-popover {
    padding: 0 !important;
    z-index: 1000 !important;
}
</style>
<style scoped lang="scss">
.user-info-panel {
    padding: 16px 24px;
    width: 192px;
    box-sizing: content-box;
    background: #ffffff;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.user-info-panel__header {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}



.user-info-panel__avatar-image {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
}

.user-info-panel__details {
    flex: 1;
    min-width: 0;
}

.user-info-panel__name {
    font-size: 18px;
    font-weight: bold;
    height: 28px;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    color: rgba(0, 0, 0, .90);
    margin-bottom: 8px;
}

.user-info-panel__org {
    font-size: 14px;
    color: #606266;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-info-panel__menu {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
}

.user-info-panel__menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.user-info-panel__menu-btn {
    cursor: pointer;
    color: var(--theme-color);
}
</style>